package com.wry.cloud.service.impl;

import com.wry.cloud.dao.PaymentMapper;
import com.wry.cloud.entity.Payment;
import com.wry.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <h1> 支付业务-业务实现类 </h1>
 *
 * @author <a href="mailto::15671496069@163.com">WeiRuYuan</a>
 * @since 2022/9/4
 */
@Service
@Slf4j
public class PaymentServiceImpl implements PaymentService {

    @Resource
    private PaymentMapper paymentMapper;

    @Override
    public Payment getPaymentById(Long id) {
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return paymentMapper.selectById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insert(Payment payment) {
        payment.setSerial((LocalDateTime.now()) + payment.getSerial());
        paymentMapper.insert(payment);
    }
}
